/* SPDX-License-Identifier: GPL-2.0 */
/**
 * Copyright (C) 2016-2020, LomboTech Co.Ltd.
 * Authors:
 *  lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#ifndef _LOMBO_MDP_PANEL_H_
#define _LOMBO_MDP_PANEL_H_

#ifndef __EOS__
#include <linux/types.h>
#endif

#include "ei_comm_doss.h"
#include "ei_comm_vbuf.h"

#ifndef __EOS__
struct drm_device;
struct drm_file;
struct drm_framebuffer;
struct drm_gem_object;
struct drm_mode_fb_cmd2;
struct drm_panel;
#endif

struct wbc_buf {
    VBUF_BUFFER buf;
    VIDEO_FRAME_INFO_S info;
#ifndef __EOS__
    struct drm_framebuffer *fb;
#endif
};

struct wbc_user_buf {
    VIDEO_FRAME_INFO_S info;
    struct os_list_head node;
};

/**
 * @_SRC_PIPE: which display pipe wb from.
 * @_SRC_CROP_X/Y/W/H: crop of src, in pixel.
 * @_DST_WIDTH/HEIGHT: wb output resolution, in pixel.
 * @_CREATE_FB_QUEUE: create fb_queue with max count of buf of queue.
 */
enum {
    DOSS_WB_PARA_KEY_SRC_PIPE = 0,
    DOSS_WB_PARA_KEY_SRC_CROP_X,
    DOSS_WB_PARA_KEY_SRC_CROP_Y,
    DOSS_WB_PARA_KEY_SRC_CROP_W,
    DOSS_WB_PARA_KEY_SRC_CROP_H,
    DOSS_WB_PARA_KEY_DST_WIDTH,
    DOSS_WB_PARA_KEY_DST_HEIGHT,
    DOSS_WB_PARA_KEY_CREATE_FB_QUEUE,
    DOSS_WB_PARA_KEY_NUM_MAX,
};

typedef struct eiWBC_CTX_S {
    VO_WBC_SOURCE_S source;
    VO_WBC_ATTR_S attr;
    VO_WBC_MODE_E mode;

    EI_U32 depth;
    EI_U32 user_buf_num;
    struct os_list_head user_buf_head;
    os_spinlock_t user_buf_lock;
    os_wait_t user_buf_wait;

    MDP_CHN_S sink;

    EI_U32 enable;
    VBUF_POOL pool;
    struct os_work_struct work;

    struct wbc_buf wq_buf[2]; /* buf in workqueue */
} WBC_CTX_S;

EI_S32 doss_vo_get_vbuf_wh(VIDEO_FRAME_INFO_S *pstFrmInfo, EI_U32 *pu32Width, EI_U32 *pu32Height);
int doss_drm_res_init(void);

EI_S32 lombo_fbdev_enable(VO_DEV VoDev, VO_INTF_TYPE_E enIntfType,
        VO_SYNC_INFO_S *pstSyncInfo, VIDEO_FRAME_INFO_S *pstFrmInfo);
EI_S32 lombo_fbdev_disable(VO_DEV VoDev);

EI_S32 doss_set_csc(VO_LAYER VoLayer, VO_CSC_S *pstCSC);
EI_S32 doss_get_csc(VO_LAYER VoLayer, VO_CSC_S *pstCSC);

EI_S32 doss_vo_get_drm_client_file(EI_BOOL en);
EI_U32 doss_vo_reset_plane_priority(EI_VOID);
EI_U32 doss_vo_get_plane_priority(VO_LAYER VoLayer);
EI_U32 doss_vo_set_plane_priority(VO_LAYER VoLayer, EI_U32 priority);

EI_U32 doss_vo_recaculate_rot_buffer_info(VIDEO_FRAME_INFO_S *pstFrameInfo,
    EI_U32 u32RotWidth, EI_U32 u32RotHeight, EI_U32 *pu32Lstr, EI_U32 *pu32Offset);
int doss_vo_setplane(VO_LAYER VoLayer, VIDEO_FRAME_INFO_S *pstFrmInfo,
    int32_t crtc_x, int32_t crtc_y, uint32_t crtc_w, uint32_t crtc_h,
    uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h);
int doss_vo_atomic_commit(EI_VOID);

EI_VOID wbc_worker(struct os_work_struct *work);
EI_S32 wbc_dev_check(EI_VOID);
EI_S32 wbc_set_param(EI_U32 key, EI_U64 value);

#endif /* _LOMBO_MDP_PANEL_H_ */

